#ifndef __PEER_H_
#define __PEER_H_

#include "xx.h"
#include "list.h"

#include <netinet/in.h>

#define	AM_CHOKING				1
#define	AM_INTERESTED			2
#define	PEER_CHOKING			4
#define	PEER_INTERESTED			8

struct peer{
	int						  choke_state;

	int						  sockfd;
	struct sockaddr_in		  peer_addr;
	char					  peer_id[21];

	time_t					  last_mesg;

//	struct peer				* next_peer;
};

int	xx_peer_list_add(list_node *list_head, char *id, char *ip, int port, int *peer_num);
//int	xx_peer_list_add(xx_peer *list_head, char *id, char *ip, int port, int *peer_num);
int	xx_peer_list_add2(list_node *list_head, in_addr_t ip, in_port_t port, int *peer_num);		//FIXME: make sure the length is right
//int	xx_peer_list_add2(xx_peer *list_head, in_addr_t ip, in_port_t port, int *peer_num);		//FIXME: make sure the length is right

void *xx_peer_start(void *arg);
void xx_peer_handle(xx_peer *peer);
int	xx_init_new_peer(xx_peer *peer);
int xx_peer_init(list_node **peer_list, fd_set *peer_fds);

#endif

